using System;
using System.Collections.Generic;
using System.Text;

namespace interfaces
{
	public static class Energy
	{
		/// <summary>
		/// electricity rate type
		/// </summary>
		public enum BEE_ElectricityRate_T
		{
			Peak_ERT,
			Medium_ERT,
			Bottom_ERT,
			NUM_ERT
		};


		/// <summary>
		/// electricity rate string header used to query energy rate table.
		/// </summary>
		public static string[] BEE_strElectricityRate = new string[]
		{
			"Peak",
			"Medium",
			"Bottom",
		};


		/// <summary>
		/// electricity table name
		/// used for query
		/// </summary>
		public static string BEE_EnergyRateTableName = "Electricity";


		/// <summary>
		/// default energy cost table
		/// used for query
		/// </summary>
        public static string BEE_DefaultEnergyCostTableName = "EcmEnergy";


		// TODO, more cities natural gas price
		/// <summary>
		/// natural gas price [RMB/GJ]
		/// 39 MJ/m3 * 3.3 RMB/m3 for Shanghai price
		/// </summary>
		public static double BEE_gasRate = 3.3/39 * 1000;


		/// <summary>
		/// operation hour for each building type
		/// the 1st dimension is accessed through interf.BEE_Building_T
		/// the 2nd dimension is accessed through Energy_BEE_ElectricityRate_T
		/// the statistics number is calculated based on following electricity rate hour rule:
		/// the fraction number is based on non-work hours electricity usage percentage.
		/// 00:00--06:00 bottom,
		/// 06:00--10:00 medium,
		/// 10:00--15:00 peak,
		/// 15:00--23:00 medium,
		/// 23:00--00:00 bottom.
		/// </summary>
		public static double[][] BEE_operationHours = new double[][]
		{
			new double[] {5,	(7 + 0.05*5),	(7*0.05)	},	// shopping mall
			new double[] {5,	(5 + 0.05*7),	(7*0.05)	},	// office
			new double[] {5,	(5 + 0.7*7),	(7*0.7)		},	// hospital
			new double[] {5,	(9 + 0.8*3),	(7*0.8)		},	// hotel
			new double[] {5,		5,				0		},	// school
			new double[] {5,		12,				7		}	// other
		};


		/// <summary>
		/// average electricity rate based on specific building type and its operation hours.
		/// </summary>
		/// <param name="rate">energy rate array, access via Energy.BEE_ElectricityRate_T</param>
		/// <param name="type">building type, defined by interf.BEE_Building_T</param>
		/// <returns>averate electricity rate</returns>
		public static double avgEleRate(double[] rate, interf.BEE_Building_T type)
		{
			// total rate hr defined rate * hours
			// total hr is the building's total energy operation hour
			double total_rate = 0, total_hr = 0;

			for (int i = 0; i < (int)Energy.BEE_ElectricityRate_T.NUM_ERT; ++i)
			{
				total_hr += BEE_operationHours[(int)type][i];
				total_rate += rate[i] * BEE_operationHours[(int)type][i];
			}

			// average rate is total rate hr divided by total hr
			// and we convert KWH to MWH
			return total_rate / total_hr * 1E+3;
		}

	}
}
